package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntAccessDeviceAsset;
import com.nt.oam.service.IAntAccessDeviceAssetService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 接入设备资产Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/device")
public class AntAccessDeviceAssetController extends BaseController {
    @Autowired
    private IAntAccessDeviceAssetService antAccessDeviceAssetService;

    /**
     * 查询接入设备资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntAccessDeviceAsset antAccessDeviceAsset) {
        startPage();
        List<AntAccessDeviceAsset> list = antAccessDeviceAssetService.selectAntAccessDeviceAssetList(antAccessDeviceAsset);
        return getDataTable(list);
    }

    /**
     * 导出接入设备资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:export')")
    @Log(title = "接入设备资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntAccessDeviceAsset antAccessDeviceAsset) {
        List<AntAccessDeviceAsset> list = antAccessDeviceAssetService.selectAntAccessDeviceAssetList(antAccessDeviceAsset);
        ExcelUtil<AntAccessDeviceAsset> util = new ExcelUtil<AntAccessDeviceAsset>(AntAccessDeviceAsset.class);
        util.exportExcel(response, list, "接入设备资产数据");
    }

    /**
     * 获取接入设备资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:query')")
    @GetMapping(value = "/{accessDeviceId}")
    public AjaxResult getInfo(@PathVariable("accessDeviceId") Long accessDeviceId) {
        return success(antAccessDeviceAssetService.selectAntAccessDeviceAssetByAccessDeviceId(accessDeviceId));
    }

    /**
     * 新增接入设备资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:add')")
    @Log(title = "接入设备资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntAccessDeviceAsset antAccessDeviceAsset) {
        return toAjax(antAccessDeviceAssetService.insertAntAccessDeviceAsset(antAccessDeviceAsset));
    }

    /**
     * 修改接入设备资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:edit')")
    @Log(title = "接入设备资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntAccessDeviceAsset antAccessDeviceAsset) {
        return toAjax(antAccessDeviceAssetService.updateAntAccessDeviceAsset(antAccessDeviceAsset));
    }

    /**
     * 删除接入设备资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:remove')")
    @Log(title = "接入设备资产", businessType = BusinessType.DELETE)
    @DeleteMapping("/{accessDeviceIds}")
    public AjaxResult remove(@PathVariable Long[] accessDeviceIds) {
        return toAjax(antAccessDeviceAssetService.deleteAntAccessDeviceAssetByAccessDeviceIds(accessDeviceIds));
    }

    /**
     * 非系统-----获取接入设备资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:query')")
    @GetMapping(value = "/details/{accessDeviceId}")
    public AjaxResult getAccessDeviceMessage(@PathVariable("accessDeviceId") Long accessDeviceId) {
        return success(antAccessDeviceAssetService.selectAccessDeviceAssetMessage(accessDeviceId));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getAccessDeviceModify(@RequestParam Long accessDeviceId) {
        return success(antAccessDeviceAssetService.selectDeviceModify(accessDeviceId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:device:edit')")
    @Log(title = "接入设备资产", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{accessDeviceId}")
    public AjaxResult editModify(@PathVariable("accessDeviceId") Long accessDeviceId) {
        int isModify = 1;
        return toAjax(antAccessDeviceAssetService.updateDeviceModify(accessDeviceId, isModify));
    }


}
